package com.example.booklist.model;

import com.example.booklist.enums.ResultCode;
import lombok.Data;

/**
 * ClassName: Result
 * Package: IntelliJ IDEA
 * Description:
 *
 * @Author 谷京京
 * @Create 2023/11/23 17:23
 * @Version 1.0
 */
@Data
public class Result<T> {
    private ResultCode code;
    private String errMsg;
    private T data;
    public static <T>Result success(T data) {
        Result result = new Result();
        result.setCode(ResultCode.SUCCESS);
        result.setErrMsg("");
        result.setData(data);
        return result;
    }
    public static <T>Result fail(String errMsg) {
        Result result = new Result();
        result.setCode(ResultCode.FALSE);
        result.setErrMsg(errMsg);
//        result.setData(data);
        return result;
    }
    public static <T>Result unlogin() {
        Result result = new Result();
        result.setCode(ResultCode.UNLOGIN);
        result.setErrMsg("用户未登录");
        result.setData(null);
        return result;
    }
}
